package com.zbkj.front.controller.merchant;

import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;
import com.zbkj.common.model.admin.SystemAdmin;
import com.zbkj.common.model.merchant.MerchantProductCategory;
import com.zbkj.common.page.CommonPage;
import com.zbkj.common.request.AgentCategorySearchRequest;
import com.zbkj.common.request.MerchantBrokerageConfigInfoRequest;
import com.zbkj.common.request.MerchantBrokerageConfigSearchRequest;
import com.zbkj.common.request.PageParamRequest;
import com.zbkj.common.request.merchant.MerchantProductCategoryRequest;
import com.zbkj.common.response.BrandAgentCategoryPageDataResponse;
import com.zbkj.common.response.MerchantBaseInfoResponse;
import com.zbkj.common.response.MerchantBrokerageConfigInfoResponse;
import com.zbkj.common.response.MerchantBrokerageConfigPageDataResponse;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.vo.MerchantConfigInfoVo;
import com.zbkj.common.vo.ProCategoryCacheVo;
import com.zbkj.service.service.CommunityBrokerageService;
import com.zbkj.service.service.MerchantProductCategoryService;
import com.zbkj.service.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 商户端商户分红设置控制器
 * +----------------------------------------------------------------------
 */
@Slf4j
@RestController
@RequestMapping("api/admin/merchant/brokerage/config")
@Api(tags = "商户端商户分红设置控制器")
public class MerchantBrokerageConfigController {

    @Autowired
    private UserService userService;

    @Autowired
    private CommunityBrokerageService communityBrokerageService;


    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<MerchantBrokerageConfigPageDataResponse>> getList(@Validated MerchantBrokerageConfigSearchRequest request,
                                                                                @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<MerchantBrokerageConfigPageDataResponse> agentCategoryCommonPage = CommonPage.restPage(communityBrokerageService.getListMerchant(request, pageParamRequest));
        return CommonResult.success(agentCategoryCommonPage);
    }


    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<MerchantBrokerageConfigInfoResponse> getInfo(@PathVariable("id") Integer id) {
        SystemAdmin systemAdmin = userService.getSystemAdminByMerchantEmployee();
        return CommonResult.success(communityBrokerageService.getInfo(systemAdmin, id));
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.UPDATE, description = "商户端修改分红信息")
    @ApiOperation(value = "新增或修改")
    @RequestMapping(value = "/edit", method = RequestMethod.POST)
    public CommonResult<String> updateConfig(@RequestBody @Validated MerchantBrokerageConfigInfoRequest request) {
        SystemAdmin systemAdmin = userService.getSystemAdminByMerchantEmployee();
        if (communityBrokerageService.updateConfig(request, systemAdmin)) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "删除商户端修改分红")
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public CommonResult<Object> delete(@PathVariable(value = "id") Integer id) {
        if (communityBrokerageService.delete(id)) {
            return CommonResult.success().setMessage("删除商户地址成功");
        }
        return CommonResult.failed().setMessage("删除商户地址失败");
    }

}



